Skip to content

fix(kilo): Fix provider integration with correct API, SDK, model IDs, and auth#172

Merged
konard merged 9 commits intomainfrom
issue-171-2a4cd573cb33
Feb 14, 2026
Merged

fix(kilo): Fix provider integration with correct API, SDK, model IDs, and auth#172
konard merged 9 commits intomainfrom
issue-171-2a4cd573cb33

Conversation

@konard
Copy link
Contributor

@konard konard commented Feb 14, 2026

Summary

Fixes #171 - --model kilo/glm-5-free was completely non-functional due to 6 compounding integration bugs.

Root Causes Found

  1. Wrong API endpoint: Used /api/gateway instead of /api/openrouter
  2. Wrong SDK: Used @ai-sdk/openai-compatible instead of @openrouter/ai-sdk-provider
  3. Wrong anonymous key: Used 'public' instead of 'anonymous'
  4. Anonymous access rejected: Kilo API requires device auth even for free models
  5. Wrong model IDs: All 6 model IDs were incorrect (e.g., z-ai/glm-5 should be z-ai/glm-5:free)
  6. No auth plugin: Users couldn't authenticate via `agent auth login`

Changes

  • `js/src/provider/provider.ts`: Fix base URL, SDK package, anonymous key, add Kilo headers, fix all model IDs
  • `js/src/auth/plugins.ts`: Add Kilo device auth plugin (OAuth device flow)
  • `js/src/cli/cmd/auth.ts`: Add Kilo to auth provider priority list
  • `js/.changeset/fix-model-routing-logging.md`: Updated changeset (minor version)
  • `docs/case-studies/issue-171/`: Comprehensive case study with root cause analysis
  • `experiments/issue-171/`: SDK integration test script

How to Use

After this fix, users need to authenticate with Kilo first:
```bash
agent auth login # Select "Kilo Gateway (Device Authorization)"
```

Then use Kilo models:
```bash
agent --model kilo/glm-5-free
agent --model kilo/minimax-m2.5-free
agent --model kilo/deepseek-r1-free
```

Upstream Issue Filed

Filed Kilo-Org/kilo#315 about anonymous access not working for completions.

Test plan

  • All local CI checks pass (lint, format, file-size)
  • SDK loads correctly with `@openrouter/ai-sdk-provider`
  • Model creation works with correct base URL
  • Device auth API initiation works
  • Models listing returns correct free models (36 free, including `z-ai/glm-5:free`)
  • All model IDs verified against live Kilo API
  • End-to-end test with authenticated Kilo token (requires browser for device auth)

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #171
@konard konard self-assigned this Feb 14, 2026
#171)

Added rawModel field to the "using explicit provider/model" log message
to help diagnose cases where the parsed model differs from what the user
specified. This aids in identifying caching issues or argument parsing
problems.

Also created comprehensive case study documentation in docs/case-studies/issue-171/
with root cause analysis (likely stale Bun module cache).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] --model kilo/glm-5-free is not working fix(logging): Add rawModel field to diagnose model routing issues Feb 14, 2026
@konard konard marked this pull request as ready for review February 14, 2026 12:07
konard and others added 2 commits February 14, 2026 13:08
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard
Copy link
Contributor Author

konard commented Feb 14, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $13.505990
  • Calculated by Anthropic: $8.513043 USD
  • Difference: $-4.992947 (-36.97%)
    📎 Log file uploaded as Gist (1274KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Contributor Author

konard commented Feb 14, 2026

Please check my feedback, and redo analysis, we still don't get this model working.

#171 (comment)

Use original requirements as a hint: #171 (comment)

Also you asked me to use commands to clean the bun cache, that don't work globally, that should be also reflected in analysis so we will not repeat these mistakes.

Ensure all changes are correct, consistent, validated, tested and fully meet all discussed requirements (check issue description and all comments in issue and in pull request). Ensure all CI/CD checks pass.

@konard konard marked this pull request as draft February 14, 2026 12:15
@konard
Copy link
Contributor Author

konard commented Feb 14, 2026

🤖 AI Work Session Started

Starting automated work session at 2026-02-14T12:15:54.992Z

The PR has been converted to draft mode while work is in progress.

This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback.

konard and others added 4 commits February 14, 2026 13:31
Root cause: The kilo provider was misconfigured with wrong API endpoint
(api/gateway instead of api/openrouter), wrong SDK package
(@ai-sdk/openai-compatible instead of @openrouter/ai-sdk-provider),
wrong anonymous API key ('public' instead of 'anonymous'), and missing
device auth support.

Changes:
- Fix base URL from /api/gateway to /api/openrouter
- Switch SDK from @ai-sdk/openai-compatible to @openrouter/ai-sdk-provider
- Change anonymous key from 'public' to 'anonymous'
- Add required Kilo headers (User-Agent, X-KILOCODE-EDITORNAME)
- Add Kilo device auth plugin for `agent auth login`
- Add Kilo to auth provider priority list

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Updated all Kilo model ID mappings to match what's actually available
on the Kilo API (https://api.kilo.ai/api/openrouter/models):

- glm-5-free: z-ai/glm-5 -> z-ai/glm-5:free (the non-:free is paid)
- Replaced glm-4.7-free (not on API) with glm-4.5-air-free (z-ai/glm-4.5-air:free)
- Removed kimi-k2.5-free (moonshot/ prefix wrong, not free on Kilo)
- Replaced minimax-m2.1-free (not on API) with minimax-m2.5-free (minimax/minimax-m2.5:free)
- giga-potato-free: giga-potato:free -> giga-potato (no :free suffix)
- trinity-large-preview: arcee/ -> arcee-ai/trinity-large-preview:free
- Added deepseek-r1-free (deepseek/deepseek-r1-0528:free)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Added:
- docs/case-studies/issue-171/README.md: Full root cause analysis with
  6 compounding failures identified, timeline, lessons learned
- docs/case-studies/issue-171/original-failure-log.txt: Original log
- experiments/issue-171/test-kilo-sdk.mjs: SDK integration test script

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard changed the title fix(logging): Add rawModel field to diagnose model routing issues fix(kilo): Fix provider integration with correct API, SDK, model IDs, and auth Feb 14, 2026
@konard konard marked this pull request as ready for review February 14, 2026 12:45
@konard
Copy link
Contributor Author

konard commented Feb 14, 2026

🤖 AI Work Session Completed

Summary of Changes

Deep investigation found 6 compounding root causes for the kilo/glm-5-free Unauthorized error. All have been fixed:

Fixes Applied

  1. Wrong API endpoint — Changed from /api/gateway to /api/openrouter (matching Kilo's actual OpenRouter-compatible API)
  2. Wrong SDK package — Changed from @ai-sdk/openai-compatible to @openrouter/ai-sdk-provider (matching what Kilo wraps internally)
  3. Wrong anonymous API key — Changed from 'public' to 'anonymous' (matching Kilo's ANONYMOUS_API_KEY constant)
  4. Missing device auth — Added Kilo device authorization plugin for agent auth login (required because anonymous access is rejected for completions)
  5. All model IDs were wrong — Verified every model ID against the live Kilo API at https://api.kilo.ai/api/openrouter/models and corrected all mappings
  6. No auth plugin — Added Kilo to the auth provider priority list so agent auth login works

Files Changed

  • js/src/provider/provider.ts — Fixed URL, SDK, key, headers, model IDs
  • js/src/auth/plugins.ts — Added KiloPlugin with device auth flow
  • js/src/cli/cmd/auth.ts — Added kilo to auth priority list
  • js/.changeset/fix-model-routing-logging.md — Updated changeset (minor version)
  • docs/case-studies/issue-171/ — Comprehensive case study with timeline, analysis, and lessons learned
  • experiments/issue-171/ — Test scripts for SDK verification

Upstream Issue Filed

CI Status

All checks passing: ✅ Changesets, ✅ Lint & Format, ✅ Unit Tests (macOS, Windows, Ubuntu)

Usage After This Fix

# First authenticate (one-time):
agent auth login  # Select "Kilo Gateway (Device Authorization)"

# Then use kilo models:
agent --model kilo/glm-5-free
agent --model kilo/deepseek-r1-free
agent --model kilo/minimax-m2.5-free

Previous Misdiagnosis Corrected

The v0.12.1 fix incorrectly attributed the failure to a stale Bun cache. The actual problem was a completely broken Kilo provider integration requiring fixes across 6 dimensions. The case study documents this to prevent similar misdiagnoses.

@konard
Copy link
Contributor Author

konard commented Feb 14, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $16.679697
  • Calculated by Anthropic: $13.775794 USD
  • Difference: $-2.903902 (-17.41%)
    📎 Log file uploaded as Gist (2984KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard merged commit 288d4e5 into main Feb 14, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--model kilo/glm-5-free is not working

1 participant